package cn.wps.moffice.main.local.filebrowser.operator.actiontrace;

import java.util.Stack;

import cn.wps.moffice.main.framework.datastorage.DataModel;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

/**
 * 路径导航栏: 对应的逻辑tracker (后进先出)
 * @author wangxiaohua.
 *
 * @param <T> 操作的实体
 */
public class ActionTrace<T> implements DataModel
{
	private static final long serialVersionUID = 1L;
    
    @SerializedName("tag")
    @Expose
    public int tag;
    
    @SerializedName("actionTrace")
    @Expose
    private Stack<T> actionTrace; 
    
    public ActionTrace(int tag)
    {
        this.tag = tag;
        this.actionTrace = new Stack<T>();
    }
    
    public void add(T t)
    {
        actionTrace.add(t);
    }
    
    public T pop()
    {
    	if (actionTrace.size() > 0){
    		  T t = actionTrace.pop();
    	        return t;
    	}
    	return null;
    }
    
    public int size()
    {
        return actionTrace.size();
    }
    
    public boolean isEmpty()
    {
        return actionTrace.isEmpty();
    }
    
    public T peek()
    {
    	if (actionTrace.size() > 0){
  		  T t = actionTrace.peek();
  	        return t;
  	}
  	return null;
    }
    
    public void clear()
    {
        actionTrace.clear();
    }
    
    @Override
    public String toString()
    {
        return "ActionTrace [tag=" + tag + ", actionTrace=" + actionTrace + "]";
    }
}
